FROM php:8.2-fpm

# 8.2 的镜像对于laravel10.x需要的扩展默认是开启的

# 查看当前使用的镜像源，进入容器后，使用 cat /etc/apt/sources.list；修改镜像源为国内，在php7.4的镜像里支持，在8.2的就不支持。
#RUN sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list && \
#    sed -i 's/security.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list && \
#    apt-get update
# 20230712 运行 docker-compose up -d 编译时上面的源替换报错：#0 0.244 sed: can't read /etc/apt/sources.list: No such file or directory

# 使用下面的方式替换镜像源
RUN echo "deb http://mirrors.aliyun.com/debian/ buster main" > /etc/apt/sources.list \
    && echo "deb http://mirrors.aliyun.com/debian/ buster-updates main" >> /etc/apt/sources.list \
    && echo "deb http://security.debian.org/debian-security buster/updates main" >> /etc/apt/sources.list \
    && apt update

RUN apt-get clean && apt-get update

# 安装 ps 工具命令
#RUN apt-get install -y procps

# 安装系统依赖
RUN apt-get update && apt-get install -y \
    # 支持正则表达式功能的开发库
    libonig-dev \ 
    libxml2-dev \
    libjpeg-dev \ 
    libzip-dev \
    libpng-dev \
    unzip \
    zip \
    git

RUN docker-php-ext-install pdo_mysql

# 配置 php
RUN cp /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini \
    && echo "date.timezone = Asia/Shanghai" >> /usr/local/etc/php/php.ini \
    && echo "memory_limit = 4096M" >> /usr/local/etc/php/php.ini \
    && echo "post_max_size = 32M" >> /usr/local/etc/php/php.ini \
    && echo "max_execution_time = 300" >> /usr/local/etc/php/php.ini \
    && sed -i 's@^.*slowlog.*$@slowlog = var/log/slow.log@' /usr/local/etc/php-fpm.d/www.conf \
    && sed -i 's@^.*request_slowlog_timeout.*$@request_slowlog_timeout = 50@' /usr/local/etc/php-fpm.d/www.conf \
    && sed -i 's@^.*request_terminate_timeout.*$@request_terminate_timeout = 300@' /usr/local/etc/php-fpm.d/www.conf

# 安装 composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \
    && composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/

# 使用 pecl 方式安装扩展
RUN pecl install redis \
    && docker-php-ext-enable redis \
    && pecl install xlswriter \
    && docker-php-ext-enable xlswriter

# 安装 nodejs
#RUN curl -o node.tar.gz https://nodejs.org/dist/latest-v14.x/node-v14.21.3-linux-x64.tar.gz \
#    && tar -xzf node.tar.gz -C /usr/local --strip-components=1 \
#    && rm node.tar.gz
#
#ENV PATH="/usr/local/bin:${PATH}"
#ENV NODE_ENV=development
#
#RUN npm install --global yarn
## 配置国内镜像源
#RUN npm config set registry https://registry.npm.taobao.org
#RUN yarn config set registry https://registry.npm.taobao.org

# 切换工作目录到项目目录
# WORKDIR /var/www/html/funny
# # 在 yarn 命令前添加 SASS_BINARY_SITE=http://npm.taobao.org/mirrors/node-sass 的目的是告诉 yarn 到淘宝的镜像去下载 node-sass 二进制文件。
# RUN SASS_BINARY_SITE=http://npm.taobao.org/mirrors/node-sass yarn \


